package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.demo.common.Result;
import com.example.demo.entity.WebPage4Block;
import com.example.demo.entity.WebPage4User;
import com.example.demo.mapper.Page4BlockControllerMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/page4block")

public class Page4BlockController {
        @Resource
        Page4BlockControllerMapper page4BlockControllerMapper;

        @PostMapping
        public Result<?> save(@RequestBody WebPage4Block webPage4Block){
            page4BlockControllerMapper.insert(webPage4Block);
            return Result.success();
        }
        @PutMapping
        public Result<?> update(@RequestBody  WebPage4Block webPage4Block){
            page4BlockControllerMapper.updateById(webPage4Block);
            return Result.success();
        }
        @GetMapping
        public List<WebPage4Block> selectList(@RequestParam int search){
            LambdaQueryWrapper<WebPage4Block> wrapper= Wrappers.<WebPage4Block>lambdaQuery();
            wrapper.eq(WebPage4Block::getPageId,search);
            return page4BlockControllerMapper.selectList(wrapper);
        }
        @DeleteMapping("/{id}")
        public Result<?> update (@PathVariable Long id){
            page4BlockControllerMapper.deleteById(id);
            return Result.success();
        }
}
